<?php
defined('BASEPATH') OR exit('No direct script access allowed');
//教练
class User extends MY_Controller {

	function __construct(){
		
		parent::__construct();
		
	}

	//start
	/**
	* @name 获取教练信息
	* @return 
	*/
	//end
	function get_info(){
		$user_id = $this->user_id;

		$this->load->model('User/CoachModel','Coach');
		$info = $this->Coach->_id_get_info($user_id);
		
		$this->data_out($info);
	}
	//start
	/**
	* @name 更新教练信息
	* @param nickName false char 名称
	* @param avatarUrl false char 头像
	* @param province false char 省份
	* @param city false char 城市
	* @param gender false char 性别
	* @return 
	*/
	//end
	function update_info(){
		$user_id = $this->user_id;
		
		$arr = array(
			'nickname'=>$this->input->post('nickName',null,''),
			'headimg'=>$this->input->post('avatarUrl',null,''),
			'province'=>$this->input->post('province',null,''),
			'city'=>$this->input->post('city',null,''),
			'sex'=>$this->input->post('gender',null,''),
		);
		
		foreach($arr as $key=>$val){
			if($val===''){
				unset($arr[$key]);
			}
		}
		if(count($arr)<=0){
			$this->err_out("请输入正确的数据");
		}
		
		
		$this->load->model('User/CoachModel','Coach');
		$this->Coach->edit($arr,"id='{$user_id}'");
		
		$this->data_out($arr);
	}
	
	
	//start
	/**
	* @name 获取所有教练
	* @param is_self false int 是否包括自身
	* @return 返回数组{id、name}对象
	*/
	//end
	function get_all(){
		$user_id = $this->user_id;
		
		$is_self = $this->input->post('is_self',null,0);
		
		
		$this->load->model('User/CoachModel','CoachModel');
		
		if($is_self){
			$res = $this->CoachModel->getAll();
		}
		else{
			$res = $this->CoachModel->getAll("id!='{$user_id}'");
		}
		
		
		
		$this->data_out($res);
	}
}
